package cn.stylefeng.guns.sys.modular.system.controller;
import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.sys.core.exception.enums.BizExceptionEnum;
import cn.stylefeng.guns.sys.modular.system.entity.BtyCheci;
import cn.stylefeng.guns.sys.modular.system.entity.BtyWlCheliang;
import cn.stylefeng.guns.sys.modular.system.model.params.CheciParam;
import cn.stylefeng.guns.sys.modular.system.model.params.CwbbParam;
import cn.stylefeng.guns.sys.modular.system.service.BtyCheciService;
import cn.stylefeng.guns.sys.modular.system.warpper.NoticeWrapper;
import cn.stylefeng.roses.core.base.controller.BaseController;
import cn.stylefeng.roses.core.util.ToolUtil;
import cn.stylefeng.roses.kernel.model.exception.RequestEmptyException;
import cn.stylefeng.roses.kernel.model.exception.ServiceException;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
/**
 * 配送管理控制器
 *
 * @author
 * @Date 2020-12-22
 */
@Controller
@RequestMapping("/checi")
public class BtyCheciController extends BaseController {

    private String PREFIX = "/modular/system/checi/";
    @Resource
    private BtyCheciService checiService;
    /**
     * 跳转到配送车次列表首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "checi.html";
    }

    /**
     * 跳转到添加配送车次
     */
    @RequestMapping("/checi_add")
    public String noticeAdd() {
        return PREFIX + "checi_add.html";
    }

    /**
     * 跳转到修改配送车次
     */
    @RequestMapping("/checi_update")
    public String noticeUpdate() {
        return PREFIX + "checi_edit.html";
    }

    /**
     * 获取配送车次列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(CheciParam checiParam) {
        Page<Map<String, Object>> list = this.checiService.list(checiParam);
        Page<Map<String, Object>> wrap = new NoticeWrapper(list).wrap();
        return LayuiPageFactory.createPageInfo(wrap);
    }

    /**
     * 新增配送车次
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(BtyCheci checi) {
        checiService.addItem(checi);
        return SUCCESS_TIP;
    }

    /**
     * 删除配送车次
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Long id) {
        this.checiService.removeById(id);
        return SUCCESS_TIP;
    }

    /**
     * 修改配送车次
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(BtyCheci checi) {
        if (ToolUtil.isOneEmpty(checi, checi.getId())) {
            throw new ServiceException(BizExceptionEnum.REQUEST_NULL);
        }
        checiService.updateItem(checi);
        return SUCCESS_TIP;
    }

    /**
     * 配送车次详情
     */
    @RequestMapping("/info")
    @ResponseBody
    public Object getThemeInfo(@RequestParam String id) {
        if (ToolUtil.isEmpty(id)) {
            throw new RequestEmptyException();
        }
        return this.checiService.getById(id);
    }

    /**
     * 根据区域获取对应的店
     */
    @RequestMapping(value = "/dmList")
    @ResponseBody
    public Object dmList() {
        List<CwbbParam> dmList = checiService.dmList();
        return dmList;
    }

    /**
     * 获取车号
     */
    @RequestMapping(value = "/cheliangList")
    @ResponseBody
    public Object cheliangList() {
        List<BtyWlCheliang> cheliangList = checiService.cheliangList();
        return cheliangList;
    }

    /**
     * 发送消息
     */
    @RequestMapping(value = "/send")
    @ResponseBody
    public Object confirmOk(@RequestParam String ids) {
        checiService.send(ids);
        return SUCCESS_TIP;
    }
}
